<?php
	$SOCIALGRAPH_ENDPOINT = "http://socialgraph.apis.google.com/lookup";
	
	$SG_CACHE = array();


	function socialgraph_query($query, $follow = 1)
        {
                global $SOCIALGRAPH_ENDPOINT, $SG_CACHE;

		if (isset($SG_CACHE[$query]))
			return $SG_CACHE[$query];

                $url = $SOCIALGRAPH_ENDPOINT . "?q=" . urlencode($query);
                if ($follow) $url .= "&fme=1";

                $result = @file_get_contents($url);

                $SG_CACHE[$query] = json_decode($result);

		return $SG_CACHE[$query];
        }
?>
